#ifndef CTREEVIEW_H
#define CTREEVIEW_H

#include "cControl.h"


class cTreeNode;

class cTreeView : public cControl
{
    public:
        cTreeView(cHwnd * hwndParent,int x,int y,int largeur,int hauteur,cHwnd * HWNDParent=NULL);
        virtual ~cTreeView();
        cTreeNode * Node;
        functionEvenement   OnSelect;
        functionEvenement   OnClick;
        functionEvenement   OnDbleClick;
        cTreeNode * GetSelectedNode();

    protected:
    private:
        bool TraitementEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,LRESULT & resultat);

};

class cTreeNode
{
    public :
        cTreeNode(cTreeView * treeview,HTREEITEM item);
        cTreeNode *  Add(string libelle);
        void        SetTextColor(int r,int v, int b){textColor=RGB(r,v,b);}
        COLORREF    GetTextColor(){return textColor;}
        void        SetTextBackgroundColor(int r,int v, int b){textBackGroundColor=RGB(r,v,b);}
        COLORREF    GetTextBackgroundColor(){return textBackGroundColor;}
        HFONT       GetFont(){return font;}
        void        SetFont(LPCSTR familly,int size,int weight,bool italic=false,bool underline=false);
        void        SetFont(HFONT font);
        Begin_Property(Texte){
            Declarations(string,Texte)
            _get(string){
                PROPERTY_PROLOGUE(cTreeNode,Texte);
                char buf[32000];
                int longueur=32000;
                TVITEM tvitem;
                tvitem.mask=TVIF_TEXT;
                tvitem.hItem=pThis->_item;
                tvitem.pszText =buf; // allocate buffer
                tvitem.cchTextMax = longueur ;// length of buffer
                TreeView_GetItem(pThis->_treeview->getHwnd(),&tvitem);
                return buf;
            }
            _set(string){
                PROPERTY_PROLOGUE(cTreeNode,Texte);
                char buf[iValue.size()];
                strcpy(buf,iValue.c_str());
                int longueur=iValue.size();
                TVITEM tvitem;
                tvitem.mask=TVIF_TEXT;
                tvitem.hItem=pThis->_item;
                tvitem.pszText =buf; // allocate buffer
                tvitem.cchTextMax = longueur ;// length of buffer
                TreeView_SetItem(pThis->_treeview->getHwnd(),&tvitem);
                return "";
            }
        }End_Property(Texte)

        Begin_Property(Data){
            Declarations(void*,Data)
            _get(void*){
                return Data;
            }
            _set(void*){
                Data=(void*)iValue;
                return Data;
            }
        }End_Property(Data)

    private :
        cTreeView * _treeview;
        HTREEITEM   _item;
        COLORREF    textColor;
        COLORREF    textBackGroundColor;
        HFONT       font;


};

#endif // CTREEVIEW_H
